import React, { Component } from 'react';
import { Image, StatusBar } from 'react-native';
import Swiper from './Swiper';
import Base from '../../utils/Base';
import Footer from './Footer';

import CommonStorage from '../../utils/CommonStorage';
import Login from '../../containers/LoginContainer';

class Start extends Component {
  async componentWillMount() {
      // CommonStorage.removeStorage('uid');
      // CommonStorage.removeStorage('tpl');
    const version = await CommonStorage.getStorage('version');
    if (version === 'NotFoundError' || version === 'ExpiredError' || version.value !== Base.version) {
      CommonStorage.saveStorage('version', Base.version);
      this.props.navigator.resetTo({
        name: 'Swiper',
        component: Swiper,
      });
      return;
    }
    const uid = await CommonStorage.getStorage('uid');
    // const tpl = await CommonStorage.getStorage('tpl');
    if (uid === 'NotFoundError' || uid === 'ExpiredError') {
      // Base.tpl = 'all';
      this.props.navigator.resetTo({
        name: 'Login',
        component: Login,
      });
      return;
    }
    this.props.navigator.resetTo({
      name: 'Footer',
      component: Footer,
    });
  }

  render() {
    return (
      <Image
        style={{
          width: Base.window.width,
          height: Base.window.height - StatusBar.currentHeight,
        }}
        source={require('../../img/LaunchImage.png')}
      />
    );
  }
}
export default Start;
